import {reactive, ref} from "vue";
import {mobileRegular, passwordRegular} from "./common";

export const passwordForm = reactive({
    ref: ref(null),
    reset: function () {
        this.data = {
            cellphone: '',
            code: '',
            password: '',
            password_confirmation: '',
        }
    },
    data: {
        cellphone: '',
        code: '',
        password: '',
        password_confirmation: '',
    },
    rule: {
        cellphone: [
            {required: true, message: '请输入手机号', trigger: 'blur'},
            {pattern: mobileRegular, message: '手机号格式不正确', trigger: 'blur'}
        ],
        code: [
            {required: true, message: '请输入验证码', trigger: 'blur'}
        ],
        password: [
            {required: true, message: '请输入密码', trigger: 'blur'},
            {pattern: passwordRegular, message: '密码格式不正确', trigger: 'blur'},
        ],
        password_confirmation: [
            {required: true, message: '请输入确认密码', trigger: 'blur'},
            {
                asyncValidator: function (rule, value, callback) {

                    if (value != passwordForm.data.password) {
                        callback('两次输入密码必须相同');
                    }
                }
            },
        ],
    },
    submit: function () {
        passwordForm.init.callback();
    },
    init: {
        callback: function () {
        }
    },
});